﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Bll;
using AspNetCs.Enumerations.Channel_Enum;
using AspNetCs.Model;

public partial class Users_AddUserLinksList : BasePage
{
    protected int id = 0;
    protected string whereStr = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserExit("Login.Aspx", "请您登录", true);
        if (Request["id"] != null)
        {
            id = StringHelper.isNumber_int(Request["id"].ToString());
        }
        if (id <= 0)
        {
            ShowMsgBack("参数传递错误！");
            Response.End();
        }
        whereStr += " channel='" + Channel_Type.memorial.ToString() + "' and typeid=" + id + " ";


        if (!Page.IsPostBack)
        {
            bind();
        }
    }
    protected void bind()
    {
        this.AspNetPager1.PageSize = 15;
        Pager p = new Pager();
        p.Obj = GridView1;
        p.TableName = "FriendSite";
        p.WhereStr = whereStr;
        p.Orderfld = "Orders";
        p.PageSize = this.AspNetPager1.PageSize;
        p.PageIndex = this.AspNetPager1.CurrentPageIndex;
        p.OrderType = "asc";
        p.ControlBind();

        this.AspNetPager1.RecordCount = p.recordcount();

    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {

        GridView1.Columns[3].HeaderText = "链接说明";
        GridView1.EditIndex = e.NewEditIndex;
        bind();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        bind();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string UpdateId = GridView1.DataKeys[e.RowIndex].Value.ToString();
        FriendSite_Model OldMd = FriendSite_Bll.CreateNew.GetModel(StringHelper.isNumber_int(UpdateId));

        TextBox LinkName = GridView1.Rows[e.RowIndex].FindControl("Txt_SiteName") as TextBox;
        TextBox LinkUrl = GridView1.Rows[e.RowIndex].FindControl("Txt_SiteUrl") as TextBox;
        TextBox Readme = GridView1.Rows[e.RowIndex].FindControl("Txt_Readme") as TextBox;
        TextBox linkOrders = GridView1.Rows[e.RowIndex].FindControl("Txt_Orders") as TextBox;

        OldMd.SiteName = StringHelper.HtmlEncrypt(LinkName.Text);
        OldMd.SiteUrl = StringHelper.HtmlEncrypt(LinkUrl.Text);
        OldMd.SiteIntro = StringHelper.HtmlEncrypt(Readme.Text);
        OldMd.Orders = StringHelper.isNumber_int(linkOrders.Text);
        FriendSite_Bll.CreateNew.update(OldMd, " and id=" + StringHelper.isNumber_int(UpdateId));
        GridView1.EditIndex = -1;
        bind();



    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string UpdateId = GridView1.DataKeys[e.RowIndex].Value.ToString();
        FriendSite_Bll.CreateNew.Delete(" and  id=" + UpdateId);
        bind();



    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bind();
    }
}
